package com.yulongtian.oneProblemEveryDay.month202303;

/**
 * https://leetcode.cn/problems/bianry-number-to-string-lcci/
 * 可
 *
 * @author yulongTian
 * @create 2023-03-01 9:19
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(printBin(0.625625));
    }

    public static String printBin(double num) {
        if (num == 0.1) {
            return "ERROR";
        }
        String ans = "0.";
        while (true) {
            num *= 2;
            if (num >= 1.0) {
                ans += "1";
                num -= 1.0;
            } else {
                ans += "0";
            }

            if (num == 0) {
                break;
            }
            if (ans.length() >= 32) {
                return "ERROR";
            }
        }
        return ans;
    }


}
